﻿<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AutomaticTaggingConfig.aspx.cs" Inherits="P3.Modules.SharePoint.AutoTag.Layouts.P3.Modules.SharePoint.AutoTag.AutomaticTaggingConfig" DynamicMasterPageFile="~masterurl/default.master" %>

<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
<script type="text/javascript">
 ExecuteOrDelayUntilScriptLoaded( getQueryStrings, "sp.js");
 var queryStringColl = null;
  function getQueryStrings() 
    {
        var requestUrl = window.location.search.toString();
        if (requestUrl != '') {
            requestUrl = requestUrl.substring(1);
            queryStringColl = new Array();
            var kvPairs = requestUrl.split('&');

            for (var i = 0; i < kvPairs.length; i++) {
                var kvPair = kvPairs[i].split('=');
                queryStringColl[kvPair[0]] = kvPair[1];
            }
        }
    }
     function GetSelectedItem()
    {
        var e = document.getElementById('<%=MultiLineDropDown.ClientID%>');
        var e1 = document.getElementById('<%=MetadataDropDown.ClientID%>');
        var propertyValue = e.options[e.selectedIndex].value + "$" + e1.options[e1.selectedIndex].value;
        var propertyName = "TagConfig_" + queryStringColl['listID'];
        var siteUrl = queryStringColl['SiteUrl'];

        var clientContext = new SP.ClientContext(siteUrl);

        var web = clientContext.get_web();
        var props = web.get_allProperties();
        props.set_item(propertyName, propertyValue);
        web.update();
        clientContext.load(web);
        clientContext.executeQueryAsync(function(){
                                         SP.UI.ModalDialog.commonModalDialogClose();
                                         }, 
                                         function(sender, args){
                                            alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
                                         });

    }
    function closeDialog() {
        SP.UI.ModalDialog.commonModalDialogClose();
    }
</script>
</asp:Content>

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<span style="margin-right: 5px; float: left;">
<table class="ms-propertysheet" border="0" width="100%" cellspacing="2px" cellpadding="5px">
<% if(!this.errorLabel.Visible) {%>  
<tr>
    <td>
        <asp:Label id="MultiLineTextfieldTitle" style="font-weight:bold" Text="Select the default multiple lines text field <br /><br />" runat="server"/>
        <asp:Label id="MultiLineTextfieldDesc" Text="HashTag values will be read from this field <br /> if this document library is configured to receive incoming emails <br/> HashTags from Email body will be inserted into this field" runat="server"/>
   
   </td>
    <td><asp:DropDownList ID="MultiLineDropDown" runat="server"></asp:DropDownList></td>
</tr>
<tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
</tr>
<tr>
   <td>
   <asp:Label id="ManagedMetaDatafieldTitle" style="font-weight:bold" Text="Select the default managed metadata field <br/>" runat="server"/>
   <asp:Label id="ManagedMetaDatafieldDesc" Text="HasTags will be inserted into this field:" runat="server"/>
   </td>
   <td><asp:DropDownList ID="MetadataDropDown" runat="server"></asp:DropDownList></td>
</tr>
<% }%>  
<tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
</tr>
<tr>
    <td colspan="2"><asp:Label id="errorLabel" runat="server" Visible ="false"/></td>
</tr>
<tr>
    <td colspan="2">
        <asp:Button runat="server" ID="button1" Text="Ok"  OnClientClick=" return GetSelectedItem()"  />
        <asp:Button runat="server" Text="Cancel" id="Button2" onClientClick="closeDialog();"></asp:Button>
    </td>
</tr>
</table>
</span>

<span style="margin-right: 5px; float: right;">
    <a href="https://www.codeplex.com/site/users/view/P3Aviation" target="_blank">
        <asp:Image ID="Image1" ImageUrl="p3_group.png" runat="server" />
    </a>
</span>
</asp:Content>

<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
Tag Configuration Page
</asp:Content>

<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server" >
Tag Configuration Page
</asp:Content>
